<div class="row">
  <div class="col-xs-12">
    <!-- PAGE CONTENT BEGINS -->
    <div class="center">
      <div class="tabbable">
        <ul class="nav nav-tabs" id="myTab">
          <%@users.each do |item|%>
              <li class="active">
                <a href="<%= admin_gps_show_path(user_id:item.id) %>">
                  <%=item.name.present? ? item.name: 'user_' + item.id.to_s  %>
                  <!--<span class="badge badge-danger"></span>-->
                </a>
              </li>
              <li class="active">
              <a href="<%= admin_gps_follow_path(user_id:item.id) %>" class="btn btn-info btn-sm">
                跟踪
              </a>
              </li>
          <%end%>
        </ul>
        <div class="row">
          <div id="admin_users">
            <%= grid(@orders, show_filters: :when_filtered) do |g|
              g.column name: "#{t 'activerecord.attributes.defaults.id'}", attribute: 'id'
              g.column name: "#{t 'activerecord.attributes.order.sr'}", attribute: 'sr'
              g.column name: "#{t 'activerecord.attributes.order.phone'}", attribute: 'phone'
              g.column name: "#{t 'activerecord.attributes.order.name'}", attribute: 'name'
              g.column name: "#{t 'activerecord.attributes.order.order_date'}", attribute: 'order_date'
              g.column name: "#{t 'activerecord.attributes.order.is_in_release'}", attribute: 'is_in_release' do |task|
                {'0'=>'有保固','1'=>'过保固'}[task.is_in_release.to_s]
              end
              g.column name: "#{t 'activerecord.attributes.order.advise'}", attribute: 'advise'
              g.column name: "#{t 'activerecord.attributes.order.total_price'}", attribute: 'total_price'

              g.column do |c|
                ddd(c.id)
              end
            end %>

          </div>
          <%if @order.present? %>
          <div class="col-xs-5">
            <div class="row">
              <div class="col-xs-6">
                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.sr" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="text" id="sr" value="<%=@order.sr%>">
                      </div>
                    </div>
                  </div>

                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.name" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="text" id="name" value="<%=@order.name%>">
                      </div>
                    </div>
                  </div>

                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.phone" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="text" id="phone" value="<%=@order.phone%>">
                      </div>
                    </div>
                  </div>

                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.order_date" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="date" id="order_date" value="<%=@order.order_date%>">
                      </div>
                    </div>
                  </div>

                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.trouble" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="text" id="order_date" value="<%=@order.trouble%>">
                      </div>
                    </div>
                  </div>
                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.content" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="text" id="order_date" value="<%=@order.content%>">
                      </div>
                    </div>
                  </div>
                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.advise" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="text" id="order_date" value="<%=@order.advise%>">
                      </div>
                    </div>
                  </div>
                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.sales_service_cost" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="text" id="order_date" value="<%=@order.sales_service_cost%>">
                      </div>
                    </div>
                  </div>
                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.component_cost" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="text" id="order_date" value="<%=@order.component_cost%>">
                      </div>
                    </div>
                  </div>
                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.service_cost" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="text" id="order_date" value="<%=@order.service_cost%>">
                      </div>
                    </div>
                  </div>
                  <div class="form-group date optional">
                    <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.total_price" %></label>

                    <div class="col-xs-12 col-sm-6">
                      <div class="clearfix">
                        <input class="date optional col-xs-12 col-sm-12" type="text" id="order_date" value="<%=@order.total_price%>">
                      </div>
                    </div>
                  </div>
              </div>

              <div class="col-xs-6">
                <div class="form-group date optional">
                  <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.manager_pic" %></label>

                  <div class="col-xs-12 col-sm-6">
                    <div class="clearfix">
                      <img class="date optional col-xs-12 col-sm-6" src="<%=@order.manager_pic%>">
                    </div>
                  </div>
                </div>


                <div class="form-group date optional">
                  <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.customer_pic" %></label>


                  <div class="col-xs-12 col-sm-6">
                    <div class="clearfix">
                      <img class="date optional col-xs-12 col-sm-6" src="<%=@order.customer_pic%>">
                    </div>

                  </div>
                </div>
                <div class="form-group date optional">
                  <label class="date optional control-label col-xs-12 col-sm-6"><%= t "activerecord.attributes.order.staff_pic" %></label>

                  <div class="col-xs-12 col-sm-6">
                    <div class="clearfix">
                      <img class="date optional col-xs-12 col-sm-6" src="<%=@order.staff_pic%>">
                    </div>
                  </div>
                </div>

              </div>
            </div>
          </div>
          <div class="col-xs-7">
            <div id="container" tabindex="0"></div>
          </div>
          <%else%>
              <div class="widget-body">
                <div class="widget-main">
                  <div class="row">
                    <div class="col-xs-12">
                      <blockquote>
                        <p>无对应人员订单</p>
                        <small>
                          请安排业务员去跑业务吧
                        </small>
                      </blockquote>
                    </div>
                  </div>
                </div>
              </div>
        <%end%>
        </div>
      </div>
    </div>
  </div>
</div>

<script type="text/javascript" data-turbolinks-eval="true">
  window.onload = init_gps();

function init_gps(){
//  获取GPS位置
  get_gps();
};

  //加载地图
  function upload_map(lineArr ,first ,last ,center){
    var map = new AMap.Map('container', {
      resizeEnable: true,
      center: center,
      zoom: 13
    });
    var marker_first = new AMap.Marker({
      icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
      position: first
    });
    var marker_last = new AMap.Marker({
      icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
      position: last
    });
    var polyline = new AMap.Polyline({
      path: lineArr,          //设置线覆盖物路径
      strokeColor: "#3366FF", //线颜色
      strokeOpacity: 1,       //线透明度
      strokeWeight: 5,        //线宽
      strokeStyle: "solid",   //线样式
      strokeDasharray: [10, 5] //补充线样式
    });
    marker_first.setMap(map);
    marker_last.setMap(map);
    polyline.setMap(map);
    //   加载窗体结构
    openInfo(map,last);
  };

  //获取 GPS信息
  function get_gps(){
    var lineArr ,first ,last ,center;
    console.log("执行-1");
      $.get("/api/homes/get_gps", {id: <%=@order.id if @order.present?%>}, function (data) {
        console.log("执行-3");
          lineArr = data.gps;
          first = data.first_add;
          last = data.last_add;
          center = data.center_add;
        //  加载地图信息
        upload_map(lineArr ,first ,last ,center);

      });
    console.log("执行-2");
  };

  //在指定位置打开信息窗体
  function openInfo(map,last) {
    //构建信息窗体中显示的内容
    var info = [];
    info.push("<div><div><img src=\" http://gps.demo.cn-su.net//system/attachments/avatars/000/000/075/original/%E6%88%AA%E5%9B%BE.png?1466419860 \"/></div> ");
    info.push("<div style=\"padding:0px 0px 0px 4px;\"><b>维修公司信息</b>");
    info.push("电话 : <%= @order.phone if @order.present?%> ");
    info.push("公司名 :<%= @order.name if @order.present?%></div></div>");
    infoWindow = new AMap.InfoWindow({
      content: info.join("<br/>")  //使用默认信息窗体框样式，显示信息内容
    });
    infoWindow.open(map, last);
  };
</script>
<style type="text/css">
  #container{
    width:1000px;
    height: 600px;
  }
</style>


